<?php
/**
 * 消息生产者
 * Copyright (c) [2019] [吴跃忠]
 * [selibra] is licensed under the Mulan PSL v1.
 * You can use this software according to the terms and conditions of the Mulan PSL v1.
 * You may obtain a copy of Mulan PSL v1 at:
 * http://license.coscl.org.cn/MulanPSL
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
 * PURPOSE.
 * See the Mulan PSL v1 for more details.
 */

namespace LeoMQ;

use Selibra\Config\Config;

class LeoMQProducer
{

    protected string $message;

    protected string $queue;

    protected string $priority;

    /**
     * @var string
     */
    protected string $mq = '';

    public function __construct($message, $queue)
    {
        $this->message = $message;
        $this->queue = $queue;
        $this->priority = MQConsts::PRIORITY_LOW;
    }


    /**
     * 发送消息
     */
    public function publish()
    {
        $producer = RealizeFactory::getProducer($this->getMq());
        $producer->publish($this->message, $this->queue, $this->getPriority());
    }

    /**
     * @param string $mq
     * @return LeoMQProducer
     */
    public function setMq(string $mq): LeoMQProducer
    {
        $this->mq = $mq;
        return $this;
    }

    /**
     * @return string
     */
    public function getMq(): string
    {
        return $this->mq;
    }

    /**
     * @return string
     */
    public function getPriority(): string
    {
        return $this->priority;
    }

    /**
     * @param string $priority
     * @return LeoMQProducer
     */
    public function setPriority(string $priority)
    {
        $this->priority = $priority;
        return $this;
    }

}